import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

//配置前端路由
const routes = [
  {path:'/cinema',component:()=>import ('../views/cinema.vue')},
  {path:'/mine',component:()=>import ('../views/login.vue')},
  {path:'/movie/detail/:id',name:"detail",component:()=>import ('../components/Detail.vue')},
  {path:'/movie',
  component:()=>import ('../views/movie.vue'),
   children : [
    {path:'nowplaying',component:()=>import('../components/NowPlaying.vue')},
    {path:'comingsoon',component:()=>import ('../components/ComingSoon.vue')},
    {path:'city',component:()=>import ('../components/City.vue')},
    {path:'search',component:()=>import ('../components/MovieSearch.vue')},
    {path:'/movie',
    beforeEnter:(to,from,next)=>{
    //从本地存储中取出上次浏览的二级路由的路径，导航守卫拦截一级路由，跳转到二级路由,若为空则跳转正在热映
      const lastpath = window.sessionStorage.getItem('lastpath')||"/movie/nowplaying"
      next(lastpath)
    }},
   ]
  },
  {path:'/*',redirect:'/movie/nowplaying'},
  
]

const router = new VueRouter({
  // base: process.env.BASE_URL,
  mode:'history',
  routes
})

export default router
